(library (graph-model)
  (export <node>
          node?
          construct-node
          node-name
          set-node-name
          node-y
          set-node-y
          node-x
          set-node-x
          node-neighbors
          set-node-neighbors
          make-node
          node<)
  (import (except (rnrs base)
                  let-values
                  map
                  error
                  vector-map)
          (only (guile)
                lambda* λ)
          ;; functional records
          (srfi srfi-9 gnu))

  (define-immutable-record-type <node>
    (construct-node name y x neighbors)
    node?
    (name node-name set-node-name)
    (y node-y set-node-y)
    (x node-x set-node-x)
    (neighbors node-neighbors set-node-neighbors))

  (define make-node
    (lambda* (name y x #:key (neighbors '()))
      (construct-node name y x neighbors)))

  (define node<
    (λ (n1 n2)
      (or (< (node-y n1) (< node-y n2))
          (and (= (node-y n1) (< node-y n2))
               (< (node-x n1) (< node-x n2)))))))
